package com.sale24h.data;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class clsLoaiHang
{
	private String maLoai;
	private String tenLoai;
	private List<clsNhomHang> lstNhomHangs;
	public String getMaLoai()
	{
		return maLoai;
	}
	public void setMaLoai(String maLoai)
	{
		this.maLoai = maLoai;
	}
	public String getTenLoai()
	{
		return tenLoai;
	}
	public void setTenLoai(String tenLoai)
	{
		this.tenLoai = tenLoai;
	}
	
	public clsLoaiHang()
	{
		lstNhomHangs=new ArrayList<clsNhomHang>();
	}
	public void InitFromJSON(JSONObject lhobj) throws JSONException
	{
		String tag_nhomhang="nhomhangs";
		
		
		this.maLoai=lhobj.getString("maloai");
		this.tenLoai=lhobj.getString("tenloai");
		
		//apply nhom hangs
		JSONArray janh=lhobj.getJSONArray(tag_nhomhang);
		for (int i = 0; i < janh.length(); i++)
		{
			JSONObject jnh=janh.getJSONObject(i);
			
				
				clsNhomHang clsnh=new clsNhomHang();
				clsnh.InitFromJSON(jnh);
				
				getLstNhomHangs().add(clsnh);
			
			
			
		}
		
	}
	@Override
	public String toString()
	{
		return this.tenLoai;
	}
	public List<clsNhomHang> getLstNhomHangs()
	{
		return lstNhomHangs;
	}
	public clsNhomHang getNhomHang(int index)
	{
		if(lstNhomHangs!=null && lstNhomHangs.size()>0 && lstNhomHangs.size()>index)
		{
			return lstNhomHangs.get(index);
		}
		return null;
	}
}
